﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.serverpackets;

namespace l1cs.server.clientpackets
{
    public class C_NewCharSelect : ClientBasePacket
    {
        private const String _C_NEW_CHAR_SELECT = "[C] C_NewCharSelect";
        private static Logger _log = Logger.getLogger( typeof( C_NewCharSelect ).FullName );

        public C_NewCharSelect( byte[] decrypt, ClientThread client )
            : base( decrypt )
        {
            client.sendPacket( new S_PacketBox( S_PacketBox.LOGOUT ) ); // 2.70C->3.0で追加
            client.CharReStart( true );
            if ( client.getActiveChar() != null )
            {
                L1PcInstance pc = client.getActiveChar();
                _log.fine( "Disconnect from: " + pc.getName() );
                ClientThread.quitGame( pc );

                lock ( pc )
                {
                    pc.logout();
                    client.setActiveChar( null );
                }
            }
            else
            {
                _log.fine( "Disconnect Request from Account : " + client.getAccountName() );
            }
        }

        override
        public String getType()
        {
            return _C_NEW_CHAR_SELECT;
        }
    }
}